package com.weixin.paleituo.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.base.ComAdapter;
import com.weixin.paleituo.bean.RoomsBean;
import com.weixin.paleituo.eventbus.CheckRoomEvent;
import com.weixin.paleituo.help.ViewHolder;
import com.weixin.paleituo.util.UIUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * Author yichao
 * Time  2018/1/12 9:27
 * Dest  售房GridViewAdapter
 */
public class LeaseHouseContentGridViewAdapter extends ComAdapter<RoomsBean> {

    private int mRoomId;

    public LeaseHouseContentGridViewAdapter(Context mContext, List<RoomsBean> mData, int roomId) {
        super(mContext, mData, R.layout.item_lease_house_layout);
        mRoomId = roomId;
    }

    @Override
    public void convert(ViewHolder holder, final RoomsBean item, int position) {
        TextView itemView = holder.getItemView(R.id.tv_item_lease_house_layout);
        ImageView imageView = holder.getItemView(R.id.iv_lease_house_layout);


        RelativeLayout relativeLayout= holder.getItemView(R.id.rl_item_lease_house_layout);
        if (item.getIsSold()==0){
            //未售
            relativeLayout.setBackgroundColor(UIUtils.getColor(R.color.c_ff7ef7bc));
            itemView.setTextColor(UIUtils.getColor(R.color.c_ff383838));
            if (mRoomId==item.getRoomId()){
                imageView.setVisibility(View.VISIBLE);

            }else {
                imageView.setVisibility(View.INVISIBLE);
            }
            relativeLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    EventBus.getDefault().post(new CheckRoomEvent(item.getRoomId()));

                //    ToastUtils.makeText(item.getRoomId()+"");

                }
            });
        }else if (item.getIsSold()==1){
            //预定
            relativeLayout.setBackgroundColor(UIUtils.getColor(R.color.c_66000000));
            itemView.setTextColor(UIUtils.getColor(R.color.c_ffffffff));


        }else if (item.getIsSold()==2){
            //已售
           // relativeLayout.setBackgroundColor(UIUtils.getColor(R.color.c_f77e86));
            relativeLayout.setBackgroundColor(UIUtils.getColor(R.color.c_66000000));
            itemView.setTextColor(UIUtils.getColor(R.color.c_ffffffff));
        }else if (item.getIsSold()==3){
            //锁定
            relativeLayout.setBackgroundColor(UIUtils.getColor(R.color.c_66000000));
            itemView.setTextColor(UIUtils.getColor(R.color.c_ffffffff));

        }

        itemView.setText(item.getRoom());










    }
}
